<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>chown</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_000_001_449">&nbsp;</a>NAME</h4><blockquote>
chown - change owner and group of a file
</blockquote><h4><a name = "tag_000_001_450">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="systypes.h.html">sys/types.h</a>&gt;
#include &lt;<a href="unistd.h.html">unistd.h</a>&gt;

int chown(const char *<i>path</i>, uid_t <i>owner</i>, gid_t <i>group</i>);
</code>
</pre>
</blockquote><h4><a name = "tag_000_001_451">&nbsp;</a>DESCRIPTION</h4><blockquote>
The
<i>path</i>
argument points to a pathname naming a file.  The user ID and group ID
of the named file are set to the numeric values contained in
<i>owner</i>
and
<i>group</i>
respectively.
<p>
On XSI-conformant systems {_POSIX_CHOWN_RESTRICTED} is always
defined, therefore:
<ul>
<p>
<li>
Changing the user ID is restricted to processes with appropriate
privileges.
<p>
<li>
Changing the group ID is permitted to a process with an effective user
ID equal to the user ID of the file, but without appropriate
privileges, if and only if
<i>owner</i>
is equal to the file's user ID
or (<b> uid_t</b> )-1
and
<i>group</i>
is equal either to the calling process' effective group ID or to
one of its supplementary group IDs.
<p>
</ul>
<p>
If the
<i>path</i>
argument refers to a regular file, the set-user-ID (S_ISUID) and
set-group-ID (S_ISGID) bits of the file mode are cleared
upon successful return from
<i>chown()</i>,
unless the call is made by a process with appropriate privileges,
in which case it is implementation-dependent whether these bits are
altered.
If
<i>chown()</i>
is successfully invoked on a file that is not a regular
file, these bits may be cleared.
These bits are defined in
<i><a href="sysstat.h.html">&lt;sys/stat.h&gt;</a></i>.
<p>
If
<i>owner</i>
or
<i>group</i>
is specified as (<b>uid_t</b>)-1 or (<b>gid_t</b>)-1
respectively, the corresponding ID of the file is unchanged.
<p>
Upon successful completion,
<i>chown()</i>
will mark for update the
<i>st_ctime</i>
field of the file.
</blockquote><h4><a name = "tag_000_001_452">&nbsp;</a>RETURN VALUE</h4><blockquote>
Upon successful completion, 0 is returned.
Otherwise, -1 is returned and
<i>errno</i>
is set to indicate the error.
If -1 is returned, no changes are made in the user ID
and group ID of the file.
</blockquote><h4><a name = "tag_000_001_453">&nbsp;</a>ERRORS</h4><blockquote>
The
<i>chown()</i>
function will fail if:
<dl compact>

<dt>[EACCES]<dd>
Search permission is denied on a component of the path prefix.

<dt>[ELOOP]<dd>
Too many symbolic links were encountered in resolving <i>path</i>.

<dt>[ENAMETOOLONG]<dd>

The length of the
<i>path</i>
argument exceeds {PATH_MAX}
or a pathname component is longer than {NAME_MAX}.

<dt>[ENOTDIR]<dd>
A component of the path prefix is not a directory.

<dt>[ENOENT]<dd>
A component of <i>path</i> does not name an existing file
or <i>path</i> is an empty string.


<dt>[EPERM]<dd>
The effective user ID
does not match the owner of the file, or the
calling process does not have appropriate privileges.

<dt>[EROFS]<dd>
The named file resides on a read-only file system.

</dl>
<p>
The
<i>chown()</i>
function may fail if:
<dl compact>

<dt>[EIO]<dd>
An I/O error occurred while reading or writing to the file system.

<dt>[EINTR]<dd>
The
<i>chown()</i>
function was interrupted by a signal which was caught.

<dt>[EINVAL]<dd>
The owner or group ID
supplied is not a value supported by the implementation.

<dt>[ENAMETOOLONG]<dd>

Pathname resolution of a symbolic link produced an intermediate result whose
length exceeds {PATH_MAX}.

</dl>
</blockquote><h4><a name = "tag_000_001_454">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_001_455">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
Because {_POSIX_CHOWN_RESTRICTED} is always defined
with a value other than -1 on XSI-conformant
systems, the error [EPERM] is always returned if the effective user ID does
not match the owner of the file, or the calling process does not have
appropriate privileges.
</blockquote><h4><a name = "tag_000_001_456">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_001_457">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="chmod.html">chmod()</a></i>,
<i><a href="systypes.h.html">&lt;sys/types.h&gt;</a></i>,
<i><a href="unistd.h.html">&lt;unistd.h&gt;</a></i>.
</blockquote><h4>DERIVATION</h4><blockquote>
Derived from Issue 1 of the SVID.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>

